package luz.javaproxy.config;

import java.util.LinkedList;
import java.util.List;

import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamImplicit;

@XStreamAlias("Proxy")
public class ProxyConfig{
	String address="127.0.0.1";	//Defaults
	int port=8080;				//Defaults
	boolean autoStart=false;	//Defaults
	@XStreamImplicit
	List<PluginConfig> pluginConfigs;
	
	public ProxyConfig() {
		pluginConfigs = new LinkedList<PluginConfig>();
	}
	
	public String getAddress(){
		return this.address;
	}
	
	public void setAddress(String address){
		this.address=address;
	}
	
	public int getPort(){
		return port;
	}
	
	public void setPort(int port){
		this.port=port;
	}
	
	public boolean getAutoStart(){
		return this.autoStart;
	}
	
	public void setAutoStart(boolean autoStart){
		this.autoStart=autoStart;
	}

	public PluginConfig getPluginConfig(String name){
		for (PluginConfig conf : pluginConfigs) {
			if (conf.name.equals(name)){
				return conf;
			}
		}
		return null;
	}
	
	public void setPluginConfig(PluginConfig pluginConfig){
		String name = pluginConfig.name;
		
		PluginConfig conf;
		for (int i = 0; i < pluginConfigs.size(); i++) {
			conf=pluginConfigs.get(i);
			if (name.equals(conf.name)){
				pluginConfigs.set(i, pluginConfig);
				return;
			}
		}
		pluginConfigs.add(pluginConfig);
	}	

	


	
	
	
}